#!/bin/sh

if [ "$#" -ne 5 ]; then
    echo "$0 PROXY_LIST ANTICAPTCHA_APIKEY SMSONLINE_APIKEY OUTPUT_FILE THREAD_COUNT"
    exit
fi

PROXY_LIST="$1"
CAPAPI="$2"
SMSAPI="$3"
OUT="$4"
CONCURRENT="$5"

function exit_function() {
  kill $(jobs -p)
  exit
}

trap 'exit_function' exit

while true;
do
  JOBS_COUNT=$(jobs -p | wc -l)
  if (( JOBS_COUNT < CONCURRENT )); then
    PROXY=$(shuf -n 1 "$PROXY_LIST")
    ./discord-account-creator.sh "$CAPAPI" "$SMSAPI" "$OUT" "$PROXY" &
  else
    sleep 1
  fi
done
